package com.xiaomai.Action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;
import com.xiaomai.entity.Category;
import com.xiaomai.entity.Classification;
import com.xiaomai.entity.UserEntity;
import com.xiaomai.server.LoginUser;
import com.xiaomai.server.LoginUserImpl;
import com.xiaomai.server.MyUser_server;

public class MyAction extends ActionSupport{
	
	private String id;
	private Classification c=new Classification();
	private String cateid;
	private List<Category> categorys;
	
	public List<Category> getCategorys() {
		return categorys;
	}

	public void setCategorys(List<Category> categorys) {
		this.categorys = categorys;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Classification getC() {
		return c;
	}

	public void setC(Classification c) {
		this.c = c;
	}

	public String Cate(){                                          
		ValueStack v=ActionContext.getContext().getValueStack();
		MyUser_server u=new MyUser_server();
		List<Category> categoryAll = u.categoryAll();
		v.setValue("#session.category", categoryAll);
		return "category_success";		
	}
	
	public String Books(){   
		ValueStack v=ActionContext.getContext().getValueStack();
		MyUser_server u=new MyUser_server();
		List<Classification> list=new ArrayList<Classification>();
		List<Classification> book= u.books();
		for (Classification classification : book) {
			if(classification.getOther_links()!=null){
				list.add(classification);
			}			
		}
		System.out.println(book);
		v.setValue("#session.books", list);
		return "books_success";		
	}
	
	public String Books1(){   
		ValueStack v=ActionContext.getContext().getValueStack();
		MyUser_server u=new MyUser_server();
		List<Classification> book1= u.books1();
		v.setValue("#request.book", book1);
		return "books1_success";		
	}
	
	public String The_latest(){   
		ValueStack v=ActionContext.getContext().getValueStack();
		MyUser_server u=new MyUser_server();
		List<Classification> latest= u.The_Latest();
		v.setValue("#session.latest", latest);
		return "latest_success";		
	}
	
	public String Sel_ling(){   
		ValueStack v=ActionContext.getContext().getValueStack();
		MyUser_server u=new MyUser_server();
		List<Classification> selling= u.The_Latest();
		v.setValue("#request.selling", selling);
		return "selling_success";		
	}
	
	public String Three(){                                          
		ValueStack v=ActionContext.getContext().getValueStack();
		MyUser_server u=new MyUser_server();
		System.out.println(id);
		Classification three = u.Three(id);
		v.setValue("#session.three", three);
		return "three_success";		
	}
	
	public String Letter(){                                          
		ValueStack v=ActionContext.getContext().getValueStack();
		MyUser_server u=new MyUser_server();
		
		Classification three = u.Three(id);
		v.setValue("#session.three", three);
		return "three_success";		
	}
	
	public String GetBookListByCateId(){
		ValueStack v=ActionContext.getContext().getValueStack();
		MyUser_server u=new MyUser_server();
		//Category c=new Category();
		//c=u.Two_categories(cateid);
		//System.out.println(c);
		// categorys = c.getCategorys();
		//if(cateid!=null){
		List<Category> CategoriesList = u.getCategoriesList(getCateid());
			List<Classification> three = u.GetBookListByCateId(getCateid());
			v.setValue("#session.datalist", three);
			v.setValue("#session.CategoriesList", CategoriesList);
			v.setValue("#session.cateName", getCatename());
		//}else{
		//	List<Classification> three = u.GetBookListByCateId(id);
		//}
		
		
		//v.set("cateName", getCatename());
		System.out.println("==================:"+getCatename());
		return "GetBookListByCateId";
	}
	
	
	
	private String catename;
	public String getCateid() {
		return cateid;
	}

	public void setCateid(String cateid) {
		this.cateid = cateid;
	}

	public String getCatename() {
		return catename;
	}

	public void setCatename(String catename) {
		this.catename = catename;
	}
}	


